package de.mfits.fireflyplayer;

import static de.mfits.fireflyplayer.storage.DbHelper.GENRE;
import static de.mfits.fireflyplayer.storage.DbHelper.ID;
import static de.mfits.fireflyplayer.storage.DbHelper.SONGS;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

public class BrowseGenresActivity extends BrowseActivity {

  private static final String TRACKS = "tracks";

  private static final String TABLE = SONGS;
  private static final String[] COLUMNS = { GENRE + " as " + ID, GENRE, "count(*) as " + TRACKS };
  private static final String SELECTION = null;
  private static final String GROUP_BY = GENRE;
  private static final String HAVING = null;
  private static final String ORDER_BY = GENRE;

  private static final int LAYOUT = R.layout.list_genres;
  private static final String[] FROM = { GENRE, TRACKS };
  private static final int[] TO = { R.id.genre, R.id.genreTracks };

  public BrowseGenresActivity() {
    super(TABLE, COLUMNS, SELECTION, GROUP_BY, HAVING, ORDER_BY, LAYOUT, FROM, TO);
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(R.string.browse_title_albums);
  }

  @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
    cursor.moveToPosition(position);
    String genre = cursor.getString(cursor.getColumnIndex(GENRE));

    Intent intent = new Intent(this, BrowseGenreSongsActivity.class);
    intent.putExtra(GENRE, genre);
    startActivity(intent);
  }
}
